#include <cppunit/config/SourcePrefix.h>

#include "TestPKBIsNextStar.h"
#include "PKB.h"
#include "Type.h"
#include "DesignExtractor.h"
#include <iostream>
#include <string>

void printParentMatrix(Type::Map::ParentMatrix& parentMatrix){
		std::cout<<"\nPARENTMATRIX\n";
	// print line matrix
	Type::Map::ParentMatrix::iterator it;
	for(it = parentMatrix.begin(); it != parentMatrix.end(); it++){
		Type::Map::ParentMap row = it->second;

		if(it == parentMatrix.begin()){
			Type::Map::ParentMap::iterator itFirstRow;
			std::cout<<"\t";
			for(itFirstRow = row.begin(); itFirstRow != row.end(); itFirstRow++){
				std::cout<<itFirstRow->first<<"\t";
			}
			std::cout<<endl;
		}

		std::cout<<it->first<<"\t";

		Type::Map::ParentMap::iterator itRow;
		for(itRow = row.begin(); itRow != row.end(); itRow++){
			std::cout<<itRow->second<<"\t";
		}
		std::cout<<endl;
	}
}

void PKBIsNextStarTest::setUp(){
}

void PKBIsNextStarTest::tearDown(){
}

/*
Procedure foo{
(1)	a = 0;
(2)	while a {
(3)		b = 0;
	}
}
*/
void PKBIsNextStarTest::test_ANP_BP_AB(){
	std::cout<<std::endl<<"PKB TestCase1  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,3);
	//set Parent Relation
	pkb->setParent(2,3);
	//set Follow Relation
	pkb->setFollows(1,2);
	//set LineEntity
	pkb->insertLineEntity(1,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(3,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	//set Next
	pkb->setNext(1,2);
	pkb->setNext(2,3);

	/*******HARD CODED COMMON PARENT START**********/
	//set CommomParent Table 
	Type::Map::ParentMatrix myCommWhileParent;
	Type::Map::ParentMap wr2;
	wr2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 2));

	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(2, wr2));

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, myCommWhileParent);

	Type::Map::ParentMatrix myCommIfParent;
	Type::Map::ParentMap ir2;
	ir2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 0));

	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(2, ir2));

	pkb->setCommon(Type::Entity::IF_LINE_ENTITY, myCommIfParent);

	//printParentMatrix(myCommWhileParent);
	//printParentMatrix(myCommIfParent);
	/*******HARD CODED COMMON PARENT END**********/
	
	/*******DE BUILD COMMON PARENT START**********/
	//DONT USE EITHER DE BUILD OR HARD CODED, COMMENT OUT ACCORDINGLY
	//THIS IS TO TEST IF DE BUILD THE CORRECT COMMON PARENT

	/*DesignExtractor* de = new DesignExtractor(pkb);
	de->updateEarliestCommonParent();*/
	/*******DE BUILD COMMON PARENT END**********/

	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,3));
}
/*
Procedure foo{
(1)	while a {
(2)		b = 0;
	}
(3)	a = 0;
}
*/
void PKBIsNextStarTest::test_ANP_BP_BA(){
	std::cout<<std::endl<<"PKB TestCase2  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,3);
	//set Parent Relation
	pkb->setParent(1,2);
	std::cout<<std::endl<<"PKB Set Parent Done  ..."<<std::endl;
	//set Follow Relation
	pkb->setFollows(1,3);
	std::cout<<std::endl<<"PKB Set Follow Done  ..."<<std::endl;
	//set LineEntity
	pkb->insertLineEntity(1,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(3,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	std::cout<<std::endl<<"PKB Set LineEntity Done  ..."<<std::endl;
	//set Next Relation
	pkb->setNext(1,2);
	pkb->setNext(2,1);
	pkb->setNext(1,3);

	/*******HARD CODED COMMON PARENT START**********/
	//set CommomParent Table 1X1
	Type::Map::ParentMatrix myCommWhileParent;
	Type::Map::ParentMap wr1;
	wr1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 1));

	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, wr1));

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, myCommWhileParent);

	Type::Map::ParentMatrix myCommIfParent;
	Type::Map::ParentMap ir1;
	ir1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 0));

	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, ir1));

	pkb->setCommon(Type::Entity::IF_LINE_ENTITY, myCommIfParent);

	//printParentMatrix(myCommWhileParent);
	//printParentMatrix(myCommIfParent);
	/*******HARD CODED COMMON PARENT END**********/
	
	/*******DE BUILD COMMON PARENT START**********/
	//DONT USE EITHER DE BUILD OR HARD CODED, COMMENT OUT ACCORDINGLY
	//THIS IS TO TEST IF DE BUILD THE CORRECT COMMON PARENT

	/*DesignExtractor* de = new DesignExtractor(pkb);
	de->updateEarliestCommonParent();*/
	/*******DE BUILD COMMON PARENT END**********/

	std::cout<<std::endl<<"PKB Set Next Done  ..."<<std::endl;
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(3,2));
}
/*
Procedure foo{
(1)	a = 0;
(2)	b = 0;
}
*/
void PKBIsNextStarTest::test_ANP_BNP(){
	std::cout<<std::endl<<"PKB TestCase3  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,2);
	//set Parent Relation
	//set Follow Relation
	pkb->setFollows(1,2);
	//set LineEntity
	pkb->insertLineEntity(1,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	//set Next
	pkb->setNext(1,2);
	//NO HARD CODED MATRIX REQUIRED
	//set CommomParent Table
	//DesignExtractor* de = new DesignExtractor(pkb);
	//de->updateEarliestCommonParent();

	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,2));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(2,1));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(1,1));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(2,2));

}
/*
Procedure foo{
(1)	if x then{
(2)     a = 0;
	else{
(3)		x = 0;
	}
}
*/
void PKBIsNextStarTest::test_AP_NAB(){
	std::cout<<std::endl<<"PKB TestCase4  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,3);
	//set Parent Relation
	pkb->setParent(1,2);
	pkb->setParent(1,3);
	//set Follow Relation
	//set LineEntity
	pkb->insertLineEntity(1,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(3,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	//set Next
	pkb->setNext(1,2);
	pkb->setNext(1,3);

	/*******HARD CODED COMMON PARENT START**********/
	//set CommomParent Table 2x2
	Type::Map::ParentMatrix myCommWhileParent;
	Type::Map::ParentMap wr1;
	wr1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 0));

	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, wr1));

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, myCommWhileParent);

	Type::Map::ParentMatrix myCommIfParent;
	Type::Map::ParentMap ir1;
	ir1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 1));

	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, ir1));

	pkb->setCommon(Type::Entity::IF_LINE_ENTITY, myCommIfParent);

	//printParentMatrix(myCommWhileParent);
	//printParentMatrix(myCommIfParent);
	/*******HARD CODED COMMON PARENT END**********/
	
	/*******DE BUILD COMMON PARENT START**********/
	//DONT USE EITHER DE BUILD OR HARD CODED, COMMENT OUT ACCORDINGLY
	//THIS IS TO TEST IF DE BUILD THE CORRECT COMMON PARENT

	/*DesignExtractor* de = new DesignExtractor(pkb);
	de->updateEarliestCommonParent();*/
	/*******DE BUILD COMMON PARENT END**********/
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,2));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(2,1));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(2,3));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,3));
}
/*
Procedure foo{
(1)	while x{
(2)		if y then{
(3)			 if x then{
(4)				a = 0;
			 else{
(5)				b = 0;
			}
		}else{
(6)			c = 0;
		}
	}
}
*/
void PKBIsNextStarTest::test_AP_BP_NNAB_CW(){
	std::cout<<std::endl<<"PKB TestCase5  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,6);
	//set Parent Relation
	pkb->setParent(1,2);
	pkb->setParent(2,3);
	pkb->setParent(2,6);
	pkb->setParent(3,4);
	pkb->setParent(3,5);
	//set Follow Relation
	//set LineEntity
	pkb->insertLineEntity(1,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(3,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(4,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(5,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(6,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	//set Next
	pkb->setNext(1,2);
	pkb->setNext(2,3);
	pkb->setNext(2,6);
	pkb->setNext(3,4);
	pkb->setNext(3,5);
	pkb->setNext(4,1);
	pkb->setNext(5,1);
	pkb->setNext(6,1);

	/*******HARD CODED COMMON PARENT START**********/
	//set CommomParent Table 3x3
	Type::Map::ParentMatrix myCommWhileParent;
	Type::Map::ParentMap wr1;
	Type::Map::ParentMap wr2;
	Type::Map::ParentMap wr3;

	wr1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 1));
	wr1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 1));
	wr1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 1));

	wr2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 1));
	wr2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 1));
	wr2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 1));

	wr3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 1));
	wr3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 1));
	wr3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 1));

	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, wr1));
	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(2, wr2));
	myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(3, wr3));

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, myCommWhileParent);

	Type::Map::ParentMatrix myCommIfParent;
	Type::Map::ParentMap ir1;
	Type::Map::ParentMap ir2;
	Type::Map::ParentMap ir3;

	ir1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 0));
	ir1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 0));
	ir1.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 0));

	ir2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 0));
	ir2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 2));
	ir2.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 2));

	ir3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 1, 0));
	ir3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 2, 2));
	ir3.insert(std::pair<Type::Index::Line, Type::Index::Line>( 3, 3));

	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(1, ir1));
	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(2, ir2));
	myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(3, ir3));

	pkb->setCommon(Type::Entity::IF_LINE_ENTITY, myCommIfParent);

	//printParentMatrix(myCommWhileParent);
	//printParentMatrix(myCommIfParent);
	/*******HARD CODED COMMON PARENT END**********/
	
	/*******DE BUILD COMMON PARENT START**********/
	//DONT USE EITHER DE BUILD OR HARD CODED, COMMENT OUT ACCORDINGLY
	//THIS IS TO TEST IF DE BUILD THE CORRECT COMMON PARENT

	/*DesignExtractor* de = new DesignExtractor(pkb);
	de->updateEarliestCommonParent();*/
	/*******DE BUILD COMMON PARENT END**********/

	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,2));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,3));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(3,1));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(1,4));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(4,5));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(5,4));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(4,6));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(6,4));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(5,6));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(6,5));
}
/*
Procedure foo{
(1)	if x then{
(2)		if y then{
(3)			while x{
(4)				if y then{
(5)					 if x then{
(6)						a = 0;
					 else{
(7)						b = 0;
					}
				}else{
(8)					c = 0;
				}
(9)				z = 0;
			}
		}else{
(10)		while y {
(11)			y = 0;
			}
		}
	}else{
(12)	while x{
(13)		y = 0;
(14)		a = 0;
(15)		while z{
(16)			a = 0;
			}
(17)		if x then {
(18)			z = 0;
			}else{
(19)			l = 0;
(20)			m = 0;
			}
		}
(21)	if x then {
(22)		z = 0;
		}else{
(23)		y = 0;
		}
(24)	k = 0;
	}
(25)l = 0;
}
*/

void PKBIsNextStarTest::test_AP_BP_NNAB_NCW(){
	std::cout<<std::endl<<"PKB TestCase6  ..."<<std::endl;
	PKB::initializeInstance();
	PKB* pkb = PKB::getInstance();
	//set Proc Table
	Type::Index::Proc indexOfProc = pkb->insertProc("foo");
	pkb->insertProcStartEnd(indexOfProc,1,25);
	//set Parent Relation
	pkb->setParent(1,2); pkb->setParent(1,12); pkb->setParent(1,21); pkb->setParent(1,24);
	pkb->setParent(2,3); pkb->setParent(2,10);
	pkb->setParent(12,13); pkb->setParent(12,14); pkb->setParent(12,15); pkb->setParent(12,17); 
	pkb->setParent(21,22); pkb->setParent(21,23);
	pkb->setParent(3,4); pkb->setParent(3,9);
	pkb->setParent(10,11);
	pkb->setParent(15,16);
	pkb->setParent(17,18); pkb->setParent(17,19); pkb->setParent(17,20);
	pkb->setParent(4,5); pkb->setParent(4,8);
	pkb->setParent(5,6); pkb->setParent(5,7);
	//set Follow Relation
	pkb->setFollows(1,25);
	pkb->setFollows(12,21); pkb->setFollows(21,24);
	pkb->setFollows(13,14); pkb->setFollows(14,15); pkb->setFollows(15,17);
	pkb->setFollows(4,9); pkb->setFollows(19,20);
	//set Next Relation
	pkb->setNext(1,2); pkb->setNext(1,12);
	pkb->setNext(2,3); pkb->setNext(2,10);
	pkb->setNext(3,4); pkb->setNext(3,25);
	pkb->setNext(10,11); pkb->setNext(10,25);
	pkb->setNext(4,5); pkb->setNext(4,8);
	pkb->setNext(5,6); pkb->setNext(5,7);
	pkb->setNext(6,9); pkb->setNext(7,9); pkb->setNext(8,9);
	pkb->setNext(12,13); pkb->setNext(12,21);
	pkb->setNext(13,14); 
	pkb->setNext(14,15);
	pkb->setNext(15,16);
	pkb->setNext(15,17);
	pkb->setNext(17,18); pkb->setNext(17,19);
	pkb->setNext(19,20);
	pkb->setNext(21,22);
	pkb->setNext(21,23);
	pkb->setNext(22,24);
	pkb->setNext(23,24);
	pkb->setNext(24,25);
	pkb->setNext(9,3);
	pkb->setNext(11,10);
	pkb->setNext(18,12);
	pkb->setNext(20,12);
	pkb->setNext(16,15);
	//set LineEntity
	//6 if entity
	pkb->insertLineEntity(1,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(2,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(4,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(5,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(17,Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(21,Type::Entity::IF_LINE_ENTITY);
	
	//4 while entity
	pkb->insertLineEntity(3,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(10,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(12,Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(15,Type::Entity::WHILE_LINE_ENTITY);
	
	//15 assign entity
	pkb->insertLineEntity(6,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(9,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(7,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(11,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(8,Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertLineEntity(13,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(18,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(14,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(19,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(16,Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertLineEntity(20,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(24,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(22,Type::Entity::ASSIGNMENT_LINE_ENTITY); pkb->insertLineEntity(25,Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(23,Type::Entity::ASSIGNMENT_LINE_ENTITY);

	/*******HARD CODED COMMON PARENT START**********/
	//set common parent while
	Type::Map::ParentMatrix myCommWhileParent;
	Type::Index::Line indexc[] = {1,2,3,4,5,10,12,15,17,21};
	Type::List::Line indexes (indexc, indexc + sizeof(indexc)/sizeof(Type::Index::Line)); 

	for (Type::List::Line::iterator iter1 = indexes.begin(); iter1 != indexes.end(); ++iter1){
		Type::Map::ParentMap wri;
		for (Type::List::Line::iterator iter2 = indexes.begin(); iter2 != indexes.end(); ++iter2){
			if ((*iter1 >= 3)&&(*iter1 <= 5)&&(*iter2 >= 3)&&(*iter2 <= 5)){
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 3));
			}else if ((*iter1 >= 12)&&(*iter1 <= 17)&&(*iter2 >= 12)&&(*iter2 <= 17)){
				if (*iter1 == 15 && *iter2 == 15){
					wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 15));
				}else{
					wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 12));
				}
			}else if(*iter1 == 10 && *iter2 == 10){
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 10));
			}else{
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 0));
			}
		}
		myCommWhileParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(*iter1, wri));
	}
	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, myCommWhileParent);
	//printParentMatrix(myCommWhileParent);

	//set common parent if
	Type::Map::ParentMatrix myCommIfParent;

	for (Type::List::Line::iterator iter1 = indexes.begin(); iter1 != indexes.end(); ++iter1){
		Type::Map::ParentMap wri;
		for (Type::List::Line::iterator iter2 = indexes.begin(); iter2 != indexes.end(); ++iter2){
			if ((*iter1 >= 2)&&(*iter1 <= 10)&&(*iter2 >= 2)&&(*iter2 <= 10)){
				if ((*iter1 >= 4)&&(*iter1 <= 5)&&(*iter2 >= 4)&&(*iter2 <= 5)){
					if(*iter1 == 5 && *iter2 == 5){
						wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 5));
					}else{
						wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 4));
					}
				}else{
					wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 2));
				}
			}else if(*iter1 == 17 && *iter2 == 17){
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 17));
			}else if(*iter1 == 21 && *iter2 == 21){
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 21));
			}else{
				wri.insert(std::pair<Type::Index::Line, Type::Index::Line>(*iter2, 1));
			}
		}
		myCommIfParent.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap>(*iter1, wri));
	}
	pkb->setCommon(Type::Entity::IF_LINE_ENTITY, myCommIfParent);
	//printParentMatrix(myCommIfParent);
	/*******HARD CODED COMMON PARENT END**********/
	
	/*******DE BUILD COMMON PARENT START**********/
	//DONT USE EITHER DE BUILD OR HARD CODED, COMMENT OUT ACCORDINGLY
	//THIS IS TO TEST IF DE BUILD THE CORRECT COMMON PARENT

	/*DesignExtractor* de = new DesignExtractor(pkb);
	de->updateEarliestCommonParent();*/
	/*******DE BUILD COMMON PARENT END**********/

	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(13,21));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(13,22));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(13,23));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(13,24));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(16,21));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(16,22));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(16,24));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(16,23));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(20,21));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(20,22));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(20,23));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(20,24));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(9,6));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(6,4));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(8,7));

	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(3,10));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(5,11));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(6,11));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(8,11));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(9,11));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(6,10));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(11,5));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(11,6));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(11,4));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(11,9));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(10,5));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(10,9));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(24,22));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(25,11));

	//extra for getFirstSibling and lastSibling
	CPPUNIT_ASSERT_EQUAL(1, pkb->getFirstSibling(1));
	CPPUNIT_ASSERT_EQUAL(3, pkb->getFirstSibling(3));
	CPPUNIT_ASSERT_EQUAL(13, pkb->getFirstSibling(17));
	CPPUNIT_ASSERT_EQUAL(19, pkb->getFirstSibling(20));
	CPPUNIT_ASSERT_EQUAL(12, pkb->getFirstSibling(24));
	CPPUNIT_ASSERT_EQUAL(1, pkb->getFirstSibling(25));
	
	CPPUNIT_ASSERT_EQUAL(9, pkb->getLastSibling(4));
	CPPUNIT_ASSERT_EQUAL(3, pkb->getLastSibling(3));
	CPPUNIT_ASSERT_EQUAL(20, pkb->getLastSibling(19));
	CPPUNIT_ASSERT_EQUAL(25, pkb->getLastSibling(1));
	CPPUNIT_ASSERT_EQUAL(24, pkb->getLastSibling(21));

}